﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LogisticsModel;

namespace LogisticsDAL
{
   public class DriverDAL
    {
        #region 司机信息维护
        /// <summary>
        /// 司机信息维护列表
        /// </summary>
        /// <returns></returns>
        public static List<Driver> GetDriverManage()
        {
            StringBuilder builder = new StringBuilder(" select * FROM driver,TruckTeam where Driver.FK_TeamID =TruckTeam.TeamID");
            List<Driver> drivers = new List<Driver>();
            SqlDataReader reader = SqlHelper.ExecuteReader(builder.ToString());
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Driver driver = new Driver
                    {
                        DriverID = Convert.ToInt32(reader["DriverID"]),
                        Name = reader["Name"].ToString(),
                        Sex=Convert.ToByte(reader["Sex"]),
                        Phone=reader["Phone"].ToString(),
                        Birth=Convert.ToDateTime(reader["Birth"]),
                        TeamName=reader["TeamName"].ToString(),
                        IDCard=reader["IDCard"].ToString(),
                        CheckInTime=Convert.ToDateTime(reader["CheckInTime"])
                    };
                    drivers.Add(driver);

                }
            }
            reader.Close();
            return drivers;

        }
        #endregion

        #region 车牌号码
        public static object GetTruckNumber(int driverid)
        {
            StringBuilder builder = new StringBuilder("select Number from Truck where Truck.TruckID=(select top 1 Contact.[FK_TruckID] from Contact where Contact.FK_DriverID=@driverid)");
            SqlParameter [] parameters={
                new SqlParameter("@driverid", driverid)
            };
            return SqlHelper.ExecuteScalar(builder.ToString(), parameters);
           
         
        }
        #endregion
    }
}
